<?php 
require 'db.php';
$UserDN=$_POST['masv'];
$login=true;
	if(!$login){
	echo 'Bạn chưa đăng nhập';
		?>
	<?php }else{?>
<div  id="divDK">
	<div class="panel-body">
	<div >
	  <p align="center">
	    <?php 
	if(!isset($UserDN)){
	}
	else
	{
	$masv=$UserDN;
	$monthi=array(); 
	$sqlmonthi=" SELECT dbo_kehoachhoithao.MAMH, dbo_monhoc.TENMH,dbo_noidung.DOI";
	$sqlmonthi.=" FROM dbo_kehoachhoithao, dbo_monhoc, dbo_nienkhoa,dbo_noidung";
	$sqlmonthi.=" WHERE dbo_kehoachhoithao.MAMH = dbo_monhoc.MAMH";
	$sqlmonthi.=" AND dbo_noidung.MAMH=dbo_monhoc.MAMH ";
	$sqlmonthi.=" AND dbo_nienkhoa.NienKhoa = dbo_kehoachhoithao.NienKhoa ";
	$sqlmonthi.=" and dbo_nienkhoa.NienKhoa='2014-2015' ";
	$sqlmonthi.=" group by MAMH ";
	$stmt = $db->prepare($sqlmonthi);
	$stmt->bindParam(1,$nienkhoa,PDO::PARAM_STR);
	$stmt->execute();
	if($stmt->execute()){
		while($r=$stmt->fetch()){
			$monthi=array_merge($monthi,array(
			array("MAMH"=> $r['MAMH'],"TENMH" => $r['TENMH'],"DOI" => $r['DOI'])
			));
	}}
	//Mang môn đơn;
	$dondangky = array();
	$sqlmondon="  SELECT dbo_sinhvien.MASV, dbo_noidung.MAMH, dbo_monhoc.TenMH, dbo_noidung.TENNHOM,dbo_noidung.MANHOM";
	$sqlmondon.=" FROM dbo_dondangky, dbo_monhoc, dbo_sinhvien, dbo_noidung";
	$sqlmondon.=" WHERE dbo_noidung.MAMH = dbo_monhoc.MAMH";
	$sqlmondon.=" AND dbo_sinhvien.MASV = dbo_dondangky.MASV";
	$sqlmondon.=" AND dbo_dondangky.MaNhom = dbo_noidung.MaNhom";
	$sqlmondon.=" and dbo_sinhvien.MASV=?";
	$stmt1 = $db->prepare($sqlmondon);
	$stmt1->bindParam(1,$masv,PDO::PARAM_STR);
	$stmt1->execute();
	if($stmt1->execute()){
		while($r1=$stmt1->fetch()){
			$dondangky=array_merge($dondangky,array(
					array("MASV"=> $r1['MASV'],"MAMH"=> $r1['MAMH'],"TenMH" => $r1['TenMH'],"TENNHOM"=>$r1['TENNHOM'],"MANHOM"=>$r1['MANHOM'])
			));
		}}
	//===========Mảng kết quả đăng ký đội thể thao
	$doidangky = array();
	$sqldoidangky="  SELECT dbo_doidangky.MADOI,TENDOI,dbo_monhoc.TENMH,dbo_noidung.TENNHOM,dbo_noidung.MAMH,dbo_noidung.MANHOM";
	$sqldoidangky.=" FROM dbo_dongdoi,dbo_doidangky,dbo_noidung,dbo_monhoc";
	$sqldoidangky.=" WHERE dbo_dongdoi.MADOI=dbo_doidangky.MADOI and dbo_monhoc.MAMH=dbo_noidung.MAMH and dbo_noidung.MANHOM=dbo_dongdoi.MANHOM and dbo_doidangky.MASV=?";
	$stmt2 = $db->prepare($sqldoidangky);
	$stmt2->bindParam(1,$masv,PDO::PARAM_STR);
	$stmt2->execute();
	if($stmt2->execute()){
		while($r2=$stmt2->fetch()){
			$doidangky=array_merge($doidangky,array(
					array("MADOI"=> $r2['MADOI'],"TENDOI"=> $r2['TENDOI'],"TENMH" => $r2['TENMH'],"TENNHOM"=>$r2['TENNHOM'],"MAMH"=>$r2['MAMH'],"MANHOM"=>$r2['MANHOM'])
			));
		}}
	?>
	
	
	
      <?php if($login){
		$i=1; 
		?>
	  <div class="row">
	<div class="form-group">
		<form  method="post" class="form-horizontal">
			
		<table id="Dachsachhht" class="table table-bordered table-hover">
			<thead><tr><th colspan="4" bgcolor="#00CCFF">
			DANH SÁCH CÁC MÔN THỂ THAO THI ĐẤU
			</th></tr></thead>
			<tr class="info"><th>STT</th><th>Tên môn thể thao</th><th>Chọn</th></tr></thead>
			<tbody>
			
			<?php foreach($monthi as $monthis){?>
			<tr>
			<td><?php echo $i++;?></td>
			<td> <?php echo $monthis['TENMH'];?></td>
			<td>
			<?php 
			if($monthis['DOI']==0){
			echo"<input type='radio' name='rdMH' id='rdDKMonThi' value='".$monthis['MAMH']."'  title='Nhấp chuột vào đây để xem thông tin chi tiết của môn thể thao thi đấu.'>";
			}
			else echo"<input type='radio' name='rdMHs' id='rdDKMonThis' value='".$monthis['MAMH']."'  title='Nhấp chuột vào đây để xem thông tin chi tiết của môn thể thao thi đấu.'>";
			?>			
			</td>
			<?php }?>
			</tbody>
		</table>
		    <?php }}?>
			
		</form>
		</div>
	  </div>
	  </div>
		
		<div class="row">
		<div class="form-group">
				
		<table id="Dachsachdk" class="table table-bordered table-hover">
			<thead><tr><th colspan="5" bgcolor="#66FFCC">
			KẾT QUẢ ĐĂNG KÝ NỘI DUNG ĐƠN
			</th></tr></thead>
			<thead>
			<tr class="info"><th>STT</th><th>Mã Môn</th><th>Tên môn thể thao</th><th>Nội dung</th><th>Xóa</th></tr></thead>
			<tbody>
			<?php $i=1;?>
			<?php foreach($dondangky as $dondk){?>
			<tr>
			<td> <?php echo $i++;?></td>
			<td> <?php echo $dondk['MAMH'];?></td>
			<td> <?php echo $dondk['TenMH'];?></td>
			<td> <?php echo $dondk['TENNHOM'];?></td>
			<td><a class="del" id="btnxoanhom" href='#' data-mamon="<?php echo $dondk['MAMH'];?>" data-manhom=<?php echo $dondk['MANHOM'];?> data-tenmh="<?php echo $dondk['TenMH'];?>"><span class="glyphicon glyphicon-trash"></span></a></td>
			<?php }?>
			
			</tbody>
		
		
		</table>
		
		</div>
		</div>

<div class="row">
		<div class="form-group">
				
		<table id="Dachsachdk" class="table table-bordered table-hover">
			<thead><tr><th colspan="5" bgcolor="#CCFFCC">
			KẾT QUẢ ĐĂNG KÝ NỘI DUNG ĐỘI
			</th></tr></thead>
			<thead>
			<tr class="info"><th>STT</th><th>Mã Môn</th><th>Tên môn thể thao</th><th>Nội dung</th><th>Xóa</th></tr></thead>
			<tbody>
			<?php $i=1;?>
			<?php foreach($doidangky as $doidk){?>
			<tr>
			<td> <?php echo $i++;?></td>
			<td> <?php echo $doidk['MAMH'];?></td>
			<td> <?php echo $doidk['TENMH'];?></td>
			<td> <?php echo $doidk['TENNHOM'];?></td>
			<td><a class="del" id="btnxoadoi" href='#' data-manhom="<?php echo $doidk['MANHOM'];?>" data-madoi=<?php echo $doidk['MADOI'];?> data-tendoi="<?php echo $doidk['TENDOI'];?>"><span class="glyphicon glyphicon-trash"></span></a></td>
			<?php }?>
			
			</tbody>
		
		
		</table>
		
		</div>
		</div>

		
	</div>
	
</div>
 <?php }?>
<?php 


?>
